﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Routing;

namespace MvcFlow.Mvc.ActionResults
{
    [Serializable]
    public class RedirectToRouteActionResult : IActionResult
    {
        private readonly Dictionary<string,object> routeValues = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);

        public string                       RouteName { get; set; }

        public IDictionary<string,object>   RouteValues
        {
            get { return routeValues; }
        }

        public ActionResult Bind(ControllerBase controllerBase)
        {
            var finalRouteValues = new RouteValueDictionary(routeValues);

            return string.IsNullOrWhiteSpace(RouteName)
                       ? new RedirectToRouteResult(finalRouteValues)
                       : new RedirectToRouteResult(RouteName, finalRouteValues);
        }
    }
}